package cn.wangzg.mybmidemo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private RadioButton rb_male;
    private RadioButton rb_female;
    private EditText et_height;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        intView();
    }

    private void intView() {
        rb_male = findViewById(R.id.rb_male);
        rb_female = findViewById(R.id.rb_female);
        et_height= findViewById(R.id.et_height);
    }

    public void btnHeight(View view){
        //1.获得性别和身高
        boolean isMale;
        if(rb_male.isChecked()){
            isMale=true;
        }else {
            isMale=false;
        }

        float height=Float.parseFloat(et_height.getText().toString());

        //2.计算
        double bz=0;
        if(isMale){
            bz=(height-80)*0.7;
            Toast.makeText(this,
                    "你是一位男性\n你的身高是"+height+"cm \n你的标准体重为"+bz+"kg",
                    Toast.LENGTH_SHORT).show();
        }else {
            bz=(height-70)*0.6;
            Toast.makeText(this,
                    "你是一位女性\n你的身高是"+height+"cm \n你的标准体重为"+bz+"kg",
                    Toast.LENGTH_SHORT).show();
        }

    }
}
